<template>
  <div class="iconWrap" v-if="datas">
      <div class="icons" v-if="btnShow!=false">
        <i :class="datas.PraiseState?'praise on':'praise'" @click.stop="toPraise()"></i>
        <i :class="datas.IsCollect?'hdol on':'hdol'" @click.stop="toCollect()"></i>
        <i v-if="Identifier" class="toMessage" @click.stop="toSession"></i>
      </div>
      <div class="close" @click.stop="close()"></div>
  </div>
</template>
<script>
import { fetch,zdUrl,chatAppId } from '../../assets/api';
import API from '../../assets/js/fetchAPI';
import Client from '../../assets/js/common';
import { Toast } from 'mint-ui';
export default {
  props: ["obj","btnShow"],
  data() {
    return {
      loginData:null,
      objId:null,
      clickObj:null,
      Identifier:null,
      datas:null
    };
  },
  created(){
    this.loginData = Client.getStore('login');
    this.clickObj = this.$store.state.clickObj;
    let storeData = this.$store.state.detailDatas;
    this.datas = storeData;
    this.Identifier = storeData.User&&storeData.User.Identifier?storeData.User.Identifier:null;
    console.log('本条地址',storeData);
    //附近
    /*if(clickObjs.type == 1){
      //行家与标点不同，点赞只是赞一整条详情，故先注销多条点赞
      if(clickObjs.index>0){
        let currentObj = storeData.MessageDetails[clickObjs.index-1];
        clickObjs.id = currentObj.PostMesssageDetailId;
        console.log('cId',currentObj.PostMesssageDetailId);
      }

    }else if(clickObjs.type == 3){
    //约见
    }*/
  },
  methods: {
    close(){
      this.$store.commit('boxShow', false);
      if(this.clickObj.goBack){
        history.back();
      }
    },
    async toPraise(){
      let postLogin = this.loginData[1],
          urls = API.praiseExpert,
          postObj = {PostMesssageId:this.clickObj.id};
      if(this.clickObj.type == 3){
        urls = API.praiseMeet;
        postObj = {AskToSeeId:this.clickObj.id};
      }
      try{
          let res = await fetch(urls,{...this.loginData[1],...postObj});
          if(res.Result.State){
            Toast('点赞成功');
          }else{
            Toast('已取消该点赞');
          }
          //console.log('点赞后台回调',res);
          this.datas.PraiseState = !this.datas.PraiseState;
          this.$store.commit('detailDatas', this.datas);
        }catch(e){
          Toast('操作失败');
      }
    },
    async toCollect(){
      let postLogin = this.loginData[1],
          urls = API.meetCollect,
          postObj = {PostMessageId:this.clickObj.id};
      if(this.clickObj.type == 3){
        urls = API.askToMeetCollect;
        postObj = {AskToSeeId:this.clickObj.id};
      }
      try{
          await fetch(urls,{...this.loginData[1],...postObj});
          if (this.datas.IsCollect){
            Toast('取消收藏');
          } else {
            Toast('收藏成功');
          }
          this.datas.IsCollect = !this.datas.IsCollect
      }catch(e){
        Toast('收藏失败');
      }
      
    },
    toSession(){
      location.href = `${zdUrl}session?resource=HJ&AppId=${chatAppId}&OpenId=${this.loginData[1].OpenId}&id=${this.Identifier}&selType=C2C`;
    }
  }
};
</script>
<style lang="less" scoped>
.iconWrap {
  padding: 0.1rem 0.15rem 0;
  position: relative;
  .icons {
    display: flex;
    i {
      display: block;
      width: 0.25rem;
      height: 0.25rem;
      border-radius: 50%;
      margin-right: 0.1rem;
      &.praise {
        background: url("../../assets/img/icon_good_off@3x.png") center no-repeat;
        background-size: cover !important;
        &.on{
          background: url("../../assets/img/icon_good_on@3x.png") center no-repeat;
        }
      }
      &.hdol {
        background: url("../../assets/img/icon_hdol-off@3x.png") center;
        background-size: cover;
        background-repeat: no-repeat;
        &.on{
          background: url("../../assets/img/icon_hdol-on@3x.png") center no-repeat;
          background-size: cover !important;
        }
      }
      &.toMessage {
        background: url("../../assets/img/icon_message@3x.png") center;
        background-size: cover;
        background-repeat: no-repeat;
      }
    }
  }
  .close {
    height: 0.25rem;
    width: 0.25rem;
    position: absolute;
    top: 0.1rem;
    right: 0.15rem;
    background: url("../../assets/img/icon_close@3x.png") center;
    background-size: cover;
    background-repeat: no-repeat;
    border-radius: 50%;
  }
}
</style>
